/*
 * 
 * 话费产出   玩家信息统计
 * 
 */
$(function(){
	loadDatas();
	loadGames();
	//初始化日期控件
  	$('#bt, #et').datetimepicker({
  		language: 'zh-CN',
	    format: 'yyyy-mm-dd hh:00',
	    autoclose: true,
	    minuteStep: 1,
	    minView: "day"
	});
});

function findAll(){
	
	$("#reset").click();
	
	$("#begin_time").val("");
	$("#end_time").val("");
	
	loadDatas();
}

//查询数据
function loadDatas(s){
	
	if(s=="search"){
		$("#page").val("");
	}
	
	//页码
	var page = $("#page").val();
	//一页显示的条数
	var pageSize = 40;
	//选择查询的条件（1:推广号 2:昵称）
	var user = $("#user").val();
	//查询的值
	var userVal = $("#userVal").val();
	//房间
	var room = $("#room").val();
	//话费面值
	var huafei = $("#huafei").val();
	//时间
	var begin = $("#begin_time").val();
	var end = $("#end_time").val();
	
//	alert(page+"; pageSize: "+pageSize+"; user:"+user+"; userVal:"+userVal+"; room:"+room+"; huafei:"+huafei+"; begin:"+begin+"; end:"+end);
	$.ajax({
		type: "post",
		data: {"page":page, "pageSize":pageSize, "user":user, "userVal":userVal, "room":room, "huafei":huafei, "begin":begin, "end":end},
		url: "../../../php/charts/huaFeiOutPut/loadUserInfoCounts.php",
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){
			$("#load").css("display","none");
			//表格数据
			var datas = msg.records;
			
			var htmlStr = "";
			if(datas.length == 0){
				htmlStr += "<tr><td colspan='5' align='center'>没查询到符合条件的数据~</td></tr>";
			}else{
				for(var i = 0; i<datas.length; i++){
					htmlStr += "<tr>";
					htmlStr += "<td>"+datas[i].time+"</td>";//时间
					htmlStr += "<td>"+datas[i].roomName+"</td>";//房间
					htmlStr += "<td><a href='../../player/playerInfo/playerDetailsInfo.php?gameId="+datas[i].gameId+"' title='查看玩家详情'>"+datas[i].gameId+"</a></td>";//推广号
					htmlStr += "<td><a href='../../player/playerInfo/playerDetailsInfo.php?gameId="+datas[i].gameId+"' title='查看玩家详情'>"+datas[i].nickName+"</a></td>";//用户昵称
					htmlStr += "<td>"+datas[i].hfmz+"</td>";//话费面值
					htmlStr += "</tr>";
				}
			}
			$("#databody").html(htmlStr);
			
			//统计数据
			var ci = msg.countInfo;
			$("#outputHuaFei").html(ci[0].allMoney==""?'￥0':'￥'+ci[0].allMoney);//合计产出
			$("#outputCount").html(ci[0].allCounts==""?0:ci[0].allCounts);//累计产出个数
			$("#userCounts").html(ci[0].userCounts==""?0:ci[0].userCounts);//累计获得用户
			$("#avgCounts").html(ci[0].avgCounts==""?0:ci[0].avgCounts);//平均获得个数
			$("#avgHuaFei").html(ci[0].avgHuaFei==""?0:ci[0].avgHuaFei);//平均话费
			
			//分页数据
			var pageInfo = msg.pageInfo;
			//总条数
			var allCount = pageInfo[0].count;
			$("#count").html(allCount);
			//总页数
			var allPage = Math.ceil(allCount/pageSize);
			if(allPage==0){
				allPage = 1;
			}
			//当前页码
			var now = pageInfo[0].page;
			
			$("#page").val(now);
			$("#nowPage").html(now);
			$("#allPage").html(allPage);
			$("#pageIpu").val("");
		}
	});
}

//加载所有游戏
function loadGames(){
	$.ajax({
		type: "post",
		url: "../../../php/sys/roomSet/loadGames.php",
		success: function(msg){
			var datas = msg.records;
			
			var html = "<option value=''>&nbsp;&nbsp;全部</option>";
			if(datas.length!=0){
				for(var i = 0; i < datas.length; i++){
					html += "<option value='"+datas[i].kindName+"'>&nbsp;&nbsp;"+datas[i].kindName+"</option>";
				}
			}
			$("#game").html(html);
		}
	});
}

//加载所有房间
function loadRooms(obj){
	var game = $(obj).val();
	$.ajax({
		type: "post",
		data: {"game":game},
		url: "../../../php/sys/roomSet/loadRooms.php",
		success: function(msg){
			var datas = msg.records;
			var html = "<option value=''>&nbsp;&nbsp;全部</option>";
			if(datas.length!=0){
				for(var i = 0; i < datas.length; i++){
					html += "<option value='"+datas[i].serverId+"'>&nbsp;&nbsp;"+datas[i].roomName+"</option>";
				}
			}
			$("#room").html(html);
		}
	});
}